﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Unis.Framework.ORM.DbSql;

namespace Unis.ORM.DbSql
{
    [Serializable]
    public class SqlParamInfo : ICloneable
    {
        // Fields
        private DbType _DbType;
        private string _Description;
        private ParameterDirection _Direction;
        private int _Length;
        private string _MappingName;
        private string _Name;
        private bool _Overcast;
        private object _Value;

        // Methods
        public SqlParamInfo()
        {
        }

        public SqlParamInfo(string name)
            : this(name, DbType.String)
        {
        }

        public SqlParamInfo(string name, DbType dbType)
        {
            this._Name = name;
            this._DbType = dbType;
            this._Direction = ParameterDirection.Input;
        }

        public SqlParamInfo(string name, object value, DbType dbType)
        {
            this._Name = name;
            this._DbType = dbType;
            this._Value = value;
            this._Direction = ParameterDirection.Input;
        }

        public SqlParamInfo(string name, DbType dbType, int length, ParameterDirection direction)
        {
            this._Name = name;
            this._DbType = dbType;
            this._Length = length;
            this._Direction = direction;
        }

        public SqlParamInfo Clone()
        {
            return (base.MemberwiseClone() as SqlParamInfo);
        }

        object ICloneable.Clone()
        {
            return base.MemberwiseClone();
        }

        public override string ToString()
        {
            return string.Concat(new object[] { "Name:", this._Name, "; Description:", this._Description, "; Direction:", this._Direction.ToString(), "; TypeName:", this._DbType, "; Length:", this._Length.ToString(), " ;Overcast:", this._Overcast.ToString() });
        }

        // Properties
        public DbType DbType
        {
            get
            {
                return this._DbType;
            }
            set
            {
                this._DbType = value;
            }
        }

        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                this._Description = value;
            }
        }

        public ParameterDirection Direction
        {
            get
            {
                return this._Direction;
            }
            set
            {
                this._Direction = value;
            }
        }

        public int Length
        {
            get
            {
                return this._Length;
            }
            set
            {
                this._Length = value;
            }
        }

        public string MappingName
        {
            get
            {
                if (string.IsNullOrEmpty(this._MappingName))
                {
                    if (this._Name.IndexOf(SqlShareHelper.SQL_XML_CFG_PARAM_PREFIX) == 0)
                    {
                        this._MappingName = this._Name.Substring(1, this._Name.Length - 1);
                    }
                    else
                    {
                        this._MappingName = this._Name;
                    }
                }
                return this._MappingName;
            }
            set
            {
                this._MappingName = value;
            }
        }

        public string Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }

        public bool Overcast
        {
            get
            {
                return this._Overcast;
            }
            set
            {
                this._Overcast = value;
            }
        }

        public object Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                this._Value = value;
            }
        }
    }
}
